﻿@model Backend.JYD.Model.TreeNodeInfo
@using Backend.JYD.Model
@{
    var child = Model;
    if (child != null)
    {
        //var nodes = this.ViewBag.TreeNodes as List<TreeNodeInfo>;
        int i = Convert.ToInt32(Html.ViewData["Index"]);
        int pi = Convert.ToInt32(Html.ViewData["LastIndex"]);
        int max = Convert.ToInt32(Html.ViewData["Max"]);
        int pmax = Convert.ToInt32(Html.ViewData["LastMax"]);
        var pbefore = Html.ViewData["Before"] as List<string>;
        var nodes = Html.ViewData["Nodes"] as List<TreeNodeInfo>;
        string cbefore = string.Empty;
    <div>
        <a href="javascript:ndclk(@child.Id)" style="width:22px;color: #333; text-decoration: none;font-size: 11px;">
        @if (pbefore != null && pbefore.Count > 0)
        {
            foreach (var pb in pbefore)
            {
            <img alt="" src="/skin/tree/@(pb).gif" style="border-right: 0px; border-top: 0px; vertical-align: middle; border-left: 0px; border-bottom: 0px;font-size: 11px;" />
            }
        }
@*        @if (pi == pmax - 1)
        {
                <img alt="" src="/skin/tree/wite.gif" style="border-right: 0px; border-top: 0px; vertical-align: middle; border-left: 0px; border-bottom: 0px;font-size: 11px;" />
        }
        else
        {
            <img alt="" src="/skin/tree/line.gif" style="border-right: 0px; border-top: 0px; vertical-align: middle; border-left: 0px; border-bottom: 0px;font-size: 11px;" />
        }*@
        @if (child.IsLeaf)
        {
            cbefore = (i == max - 1) ? "joinbottom" : "join";
            <img alt="" src="/skin/tree/@(cbefore).gif" style="border-right: 0px; border-top: 0px; vertical-align: middle; border-left: 0px; border-bottom: 0px;font-size: 11px;" />
        }
        else
        {
            cbefore = (i == max - 1) ? (child.Expanded ? "minusbottom" : "plusbottom") : (child.Expanded ? "minus" : "plus");
            <img alt="" src="/skin/tree/@(cbefore).gif" id="@("jgroupTree" + child.Id)" style="border-right: 0px; border-top: 0px; vertical-align: middle; border-left: 0px; border-bottom: 0px;font-size: 11px;"/>
            cbefore = (i == max - 1) ? "wite" : "line";
        }
        </a>
        <a   href="javascript:ndclk(@child.Id)" style="color: #333; text-decoration: none;font-size: 11px;">
            <img alt="" src="/skin/tree/@(child.Expanded ? "folder_group_open" : "folder_group_close").gif" id="@("igroupTree" + child.Id)" style="border-right: 0px; border-top: 0px; vertical-align: middle; border-left: 0px; border-bottom: 0px;font-size: 11px;"/>
        </a>
        <a id="@("sgroupTree" + child.Id)"  onmouseout="javascript:this.style.textDecoration='none';"   onmouseover="javascript:this.style.textDecoration='underline';"  @(string.IsNullOrWhiteSpace(child.NodeUrl) ? string.Empty : "href = \"" + child.NodeUrl + "\"")  style="padding-right: 2px; padding-left: 2px; padding-bottom: 1px; padding-top: 1px; white-space: nowrap;color: #333; text-decoration: none;font-size: 11px;">@child.Name</a>
    </div>
        if (!child.IsLeaf)
        {
            List<TreeNodeInfo> childNodes = nodes.FindAll(r => r.ParentId == child.Id);
        <div id="@("dgroupTree" + child.Id)" style="overflow: hidden;display: @(child.Expanded ? "block" : "none");font-size: 11px;">
        @for (int j = 0; j < childNodes.Count; j++)
        {
            var before = new List<string>();
            if (pbefore != null)
            {
                before.AddRange(pbefore);
            }
            if (!string.IsNullOrWhiteSpace(cbefore))
            {
                before.Add(cbefore);
            }
            var node = childNodes[j];
            var data = new ViewDataDictionary();
            data.Add("Index", j);
            data.Add("LastIndex", i);
            data.Add("LastMax", max);
            data.Add("Max", childNodes.Count);
            data.Add("Nodes", nodes);
            data.Add("Before", before);
            Html.RenderPartial("TreeChildNode", node, data);
            @*<div>
            @if (i == max - 1)
            {
                    <img alt="" src="/skin/tree/wite.gif" style="border-right: 0px; border-top: 0px; vertical-align: middle; border-left: 0px; border-bottom: 0px;font-size: 11px;" />
            }
            else
            {
                <img alt="" src="/skin/tree/line.gif" style="border-right: 0px; border-top: 0px; vertical-align: middle; border-left: 0px; border-bottom: 0px;font-size: 11px;" />
            }
            @if (j == childNodes.Count - 1)
            {
                <img alt="" src="/skin/tree/joinbottom.gif" style="border-right: 0px; border-top: 0px; vertical-align: middle; border-left: 0px; border-bottom: 0px;font-size: 11px;" />
            }
            else
            {
                <img alt="" src="/skin/tree/join.gif" style="border-right: 0px; border-top: 0px; vertical-align: middle; border-left: 0px; border-bottom: 0px;font-size: 11px;" />
            }
            <a  href=javascript:ndclk(@node.Id) style="color: #333; text-decoration: none;font-size: 11px;">
                <img id="@("igroupTree" + node.Id)" alt="" src="/skin/tree/@(node.Expanded ? "folder_group_open" : "folder_group_close").gif" style="border-right: 0px; border-top: 0px; vertical-align: middle; border-left: 0px; border-bottom: 0px;font-size: 11px;" />
            </a>
            <a id="@("sgroupTree" + node.Id)" onclick=javascript:selectNode(@node.Id);  onmouseout="javascript:this.style.textDecoration='none';"   onmouseover="javascript:this.style.textDecoration='underline';"  @(string.IsNullOrWhiteSpace(node.NodeUrl) ? string.Empty : "href = \"" + node.NodeUrl + "\"")  style="padding-right: 2px; padding-left: 2px; padding-bottom: 1px; padding-top: 1px; white-space: nowrap;color: #333; text-decoration: none;font-size: 11px;">@node.Name</a>
            </div>*@
        }
        </div>
    }
    }
}